﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Business.Models;
using System.Data;

namespace Business.DAO
{
    public class DiaDiemDAO
    {
        private ISSContext db = new ISSContext();
        public List<DiaDiem> GetAll()
        {
            return db.DiaDiems.ToList();
        }

        public DiaDiem Get(int id)
        {
            DiaDiem diadiem = db.DiaDiems.Find(id);
            return diadiem;
        }

        public int Create(DiaDiem diadiem)
        {
            try
            {
                db.DiaDiems.Add(diadiem);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Edit(DiaDiem diadiem)
        {
            try
            {
                db.Entry(diadiem).State = EntityState.Modified;
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Delete(int id)
        {
            try
            {
                DiaDiem diadiem = db.DiaDiems.Find(id);
                db.DiaDiems.Remove(diadiem);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
    }
}